﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Quizz.DataRepository.Models;
using System.Data.Linq;

namespace Quizz.Service.Services
{
    public class RoleService : QuizzDomainService<QuizzDataContext>
    {
        public Role GetById(long id){
            return CompiledRoleService.GetById(this.DataContext, id);
        }

        public IEnumerable<Role> GetAll(){
            return CompiledRoleService.GetAll(DataContext);
        }
    }

    internal static class CompiledRoleService{
        public static Func<QuizzDataContext, long, Role> GetById = CompiledQuery.Compile<QuizzDataContext, long, Role>((ctx, id) => ctx.Roles.FirstOrDefault(r => r.Id == id));
        public static Func<QuizzDataContext, IEnumerable<Role>> GetAll = CompiledQuery.Compile<QuizzDataContext, IEnumerable<Role>>(ctx => ctx.Roles.OrderBy(r => r.Id));
    }
}
